package com.lyf.Server.Impl;

import ch.qos.logback.core.joran.conditional.ElseAction;
import com.lyf.Dao.EmployeeDao;
import com.lyf.Dao.Impl.EmployeeDaoImpl;
import com.lyf.Entity.Employee;
import com.lyf.Server.EmployeeServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmployeeServerImpl implements EmployeeServer {
    private Logger logger = LoggerFactory.getLogger(EmployeeServerImpl.class);

    @Autowired
    private EmployeeDao employeeDao;
    /*
    * 查询集合
    * */
    @Override
    public List<Employee> EmployeeList() {
        try {
            return employeeDao.EmployeeList();
        } catch (Exception ex){
            logger.error(ex.getMessage());
        }
        return null;
    }
    /*
    * 多添加
    * */
    @Override
    public int AddEmployee(List<Employee> employees) {
        try {
            int count = 0;
            for (Employee employee:employees) {
                count += employeeDao.AddEmployee(employee);
            }
            return count;
        }catch (Exception ex){
            logger.error(ex.getMessage());
        }
        return 0;
    }
    /*
    * 多修改(地址和设置修改时间)
    * */
    @Override
    public int UpdateEmployee(List<Employee> employees) {
        try {
            int count = 0;
            for (Employee employee:employees) {
                count += employeeDao.UpdateEmployee(employee);
            }
            return count;
        }catch (Exception ex){
            logger.info(ex.getMessage());
        }
        return 0;
    }
    /*
    * 多删除
    * */
    @Override
    public int DeleteEmployee(List<Employee> employees) {
        try {
            int count = 0;
            for (Employee employee:employees) {
                count += employeeDao.DeleteEmployee(employee);
            }
        }catch (Exception ex){
            logger.error(ex.getMessage());
        }
        return 0;
    }
}
